package cn.itsource.hrm.web.controller;

import cn.itsource.hrm.document.CourseDoc;
import cn.itsource.hrm.query.CourseQuery;
import cn.itsource.hrm.service.ISearchService;
import cn.itsource.hrm.util.AjaxResult;
import cn.itsource.hrm.util.PageList;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
public class SearcherController {

    @Autowired
    private ISearchService searchService;
    /**
     * 课程发布
     */
    @PreAuthorize("hasAuthority('es:online')")
    @RequestMapping(value="/search/onLineCourse",method= RequestMethod.POST)
    public AjaxResult onLineCourse(@RequestBody CourseDoc doc){

        searchService.save(doc);
        
        return AjaxResult.me();

    }
    /**
     * 到ES搜索课程
     */
    @RequestMapping(value="/es/searchCourse",method= RequestMethod.POST)
    public AjaxResult searchCourse(@RequestBody CourseQuery query){

        AjaxResult result = searchService.searchCourse(query);

        return result;

    }
}
